package com.zj.mq.demo.consumer;

import com.rabbitmq.client.Channel;
import com.zj.mq.demo.entity.Order;
import com.zj.mq.demo.service.OrderService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderConsumer {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = "queue.order.dlx")
    public void getMyMessage(Message message, Channel channel) {
        String s = new String(message.getBody());
        int i = Integer.parseInt(s);
        Order order = orderService.getById(i);
        if (order.isPay()) {
            System.out.println("订单" + i + "已经支付");
        } else {
            orderService.timeout(i);
            System.out.println("订单" + i + "已经过期");
        }
    }
}
